package cn.dy.sbo.dao;

import org.springframework.stereotype.Component;
import org.springside.modules.orm.hibernate.HibernateDao;
import org.hibernate.Query;
import org.hibernate.transform.Transformers;

import cn.dy.sbo.api.PartnerDao;
import cn.dy.sbo.model.Partner;
import cn.dy.sbo.vo.DropListVO;

import java.util.List;

@Component
public class PartnerDaoHibernate  extends HibernateDao<Partner, Long> implements PartnerDao{

    public List<DropListVO> findbyName(String cusName) {
        Query query = super.getSession().createQuery("select id as id, cardCode as code, cardName as name,'' as enname from Partner where cardName like '%" + cusName +"%'");
		List<DropListVO> list = null;
		try{
		list = (List<DropListVO>) query.setResultTransformer(Transformers.aliasToBean(DropListVO.class)).list();
		}catch(Exception e){
			e.printStackTrace();
		}
		return list;
    }

    public List<DropListVO> findByCode(String code) {
        Query query = super.getSession().createQuery("select id as id, cardCode as code, cardName as name,'' as enname from Partner where cardCode like '%" + code +"%'");
		List<DropListVO> list = null;
		try{
		list = (List<DropListVO>) query.setResultTransformer(Transformers.aliasToBean(DropListVO.class)).list();
		}catch(Exception e){
			e.printStackTrace();
		}
		return list;
    }
}
